package com.ruoyi.common.weChatRobot.template;

import com.ruoyi.common.weChatRobot.constant.WechatRobotEnum;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.internet.MimeMessage;

public class QicqMailTemplate {
    private JavaMailSender mailSender;

    public QicqMailTemplate(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     * 发送邮件
     *
     * @param mail    邮件
     * @param title   标题
     * @param content 内容
     */
    public void sendMail(String mail, String title, String content) {
        try {
            // 简单邮件信息类
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            // HTML邮件信息类
            MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage);
            mimeMessageHelper.setFrom(WechatRobotEnum.MAIL_DEVELOPERS.getUrl());
            // 昵称
            mimeMessageHelper.setTo(mail);
            mimeMessageHelper.setSubject(title);
            mimeMessageHelper.setText(content,true);

           /* mimeMessageHelper.setText("<h1>恭喜入驻成功，点击激活</h1>" + "<a href='http://localhost:8080/shop/active/" + shopId + "'>点击该链接激活店铺</a>", true);*/
            mailSender.send(mimeMessage);
        } catch (Exception e) {
            throw new RuntimeException("邮件发送失败");
        }
    }

}
